<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->


    <link href="__ADMIN_TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        form .input-order {
            margin-bottom: 0px;
            padding: 0 2px;
            width: 42px;
            font-size: 12px;
        }

        td{
            padding:5px!important;
        }

        .li{
            height: 15px;
            width: 15px;
            line-height: 15px;
            text-align: center;
            background: #aaa;
            color: #fff;
            font-weight: bold;
            font-size: 12px;
            display: inline-block;
            border-radius: 2px;
            cursor:pointer;
            margin-right: 5px;
        }

        form .input-order:focus {
            outline: none;
        }

        .table-actions {
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 0px;
        }

        .table-list {
            margin-bottom: 0px;
        }

        .form-required {
            color: red;
        }
    </style>
    <script type="text/javascript">
        //全局变量
        var GV = {
            ROOT: "__ROOT__/",
            WEB_ROOT: "__WEB_ROOT__/",
            JS_ROOT: "static/js/",
            APP: '{$Request.module}'/*当前应用名*/
        };
    </script>
    <script src="__ADMIN_TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
    <script src="__STATIC__/js/wind.js"></script>
    <script src="__ADMIN_TMPL__/public/assets/js/bootstrap.min.js"></script>
    <script>
        Wind.css('artDialog');
        Wind.css('layer');
        $(function () {
            $("[data-toggle='tooltip']").tooltip({
                container:'body',
                html:true,
            });
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
        });
    </script>
    <if condition="APP_DEBUG">
        <style>
            #think_page_trace_open {
                z-index: 9999;
            }
        </style>
    </if>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:cmf_plugin_url('QbtRegion://AdminIndex/index')}">地区列表</a></li>
        <!--<li><a href="{:cmf_plugin_url('DbBackup://AdminIndex/lists')}">添加</a></li>-->
    </ul>
    <form action="" method="post" class="margin-top-20">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <!--<th>ID</th>-->
                <th>名称</th>
                <th>行政区代码</th>
                <td width="120">操作</td>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="item">
                <tr>
                    <td>
                        <if condition="$item['isend'] ==1">
                        <span class="li" onclick="ajaxaddr(this,{$item['id']})">+</span>
                        </if>
                        {$item.name}</td>
                    <td>{$item.code}</td>
                    <td style="width: 200px;">
                        <if condition="$item['level'] !=3 && $item['pid'] !=1 && $item['pid'] !=18">
                            <a href="{:cmf_plugin_url('QbtRegion://AdminIndex/add',['id'=>$item['id'],'level'=>$item['level']])}">添加子分类</a>
                        </if>
                        <a href="{:cmf_plugin_url('QbtRegion://AdminIndex/edit',['id'=>$item['id']])}">编辑</a>
                        <a class="js-ajax-delete" href="{:cmf_plugin_url('QbtRegion://AdminIndex/del',['id'=>$item['id']])}">删除</a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/noty/noty-2.4.1.js"></script>
<script>
    function ajaxaddr(a,id){
        let e = $(a).html();
        if (e==='+'){
            $(a).html('-');
            $.ajax({
                type: "GET",
                url: "{:cmf_plugin_url('QbtRegion://AdminIndex/ajaxget')}",
                data: {id:id},
                dataType: "json",
                success: function(data){
                    console.log(data);
                    var str ='';
                    for (x in data) {
                        var child = '';
                        var bot = '';
                        var s = '└─────';
                        if (data[x].level==3){
                            s = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─────';
                        }
                        if (data[x].level != 3 && data[x].pid != 1 && data[x].pid != 18 && data[x].isend == 1){
                            child = '<a href="{:cmf_plugin_url(\'QbtRegion://AdminIndex/add\')}?id='+data[x].id+'&level='+data[x].level+'">添加子分类</a>';
                            bot = '<span class="li" onclick="ajaxaddr(this,'+data[x].id+')">+</span>';
                        }
                        str += '<tr class="id'+data[x].pid+'">\n' +
                '                    <td>'+s+bot+data[x].name+'</td>\n' +
                '                    <td>'+data[x].code+'</td>\n' +
                '                    <td style="width: 200px;">\n' +child+
                '                        <a href="{:cmf_plugin_url(\'QbtRegion://AdminIndex/edit\')}?id='+data[x].id+'">编辑</a>\n' +
                '                        <a class="js-ajax-delete" href="{:cmf_plugin_url(\'QbtRegion://AdminIndex/del\')}?id='+data[x].id+'">删除</a>\n' +
                '                    </td>\n' +
                '                </tr>';
                    };
                    $(a).parent().parent().after(str);
                }
            });
        }else{
            $(".id"+id).remove();
            $(a).html('+');
        }
    };
</script>
</body>
</html>